﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MiserBlogData.Entities;

namespace MiserBlogMVC.Models
{
    public class ArticleModelBinder : BinderBase
    {

        public override object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
        {
            if (controllerContext.HttpContext.User.Identity is UserVIPIdentity && 
                controllerContext.HttpContext.User.Identity.IsAuthenticated)
            {
                UserVIPIdentity userIdentity = (UserVIPIdentity)controllerContext.HttpContext.User.Identity;
                Article article = new Article();
                //article.Title = GetValue<string>(bindingContext, "Title");
                //article.CDate = DateTime.Now;
                //article.Categories.Id = GetValue<int>(bindingContext, "Id");
                //article.Comments = 0;
                //article.Content = GetValue<string>(bindingContext, "Content");
                //article.Person.Id = userIdentity.Person.Id;
                //article.UDate = article.CDate;
                //article.Visits = 0;
                //article.Categories.Id = GetValue<int>(bindingContext, "State");
                //article.State = GetValue<int>(bindingContext, "State"); //(int)DataSate.Start;
                //article.Summary
                //article.Tags
                //article.TimeTag

                return article;
            }
            return null;
            //article.Person.Id = controllerContext.HttpContext.User.Identity.
        }
    }
}